
import pagination from '@/views/pagination'  //分页组件

import agentHttp from '@/utils/agentHttp.js'
import {debounce,timestampToTime,initDataTime} from '@/utils/index.js'
import  {confirm} from '@/utils/confirm.js'    //二次确认组件
import Popup from './edit.vue'     
export default {
  name: 'TestCarManage',
  created(){
   this.seachData()
  },
  components:{
    Popup,
    pagination,
    confirm   
  },
  data() {
  	return {
      //搜索字段
  		searchForm:{     //给form表单绑定的数据对象
  			dealerName:"",   //融资经销商
        orderNumber:"",//订单号
        startDate:"",   //时间段
        endDate:"",        
        status:'',       //selsct表单的选择  
        reviewStatus:'',    //复审状态的选择
      },
       mortgageOrderExtendId:'',//传递给子组件的id,
       buttonValue:'',    //传递给子组件的button内容
      //表格字段
      tableData: [],
      orderCode:{}, //订单状态
      reviewStatus:{},//复审状态
      dialogSendData:{
        isAdd:true,                //是否为编辑或者新增  true是   false否
        dialogFormVisible:false,   //弹窗是否显示        true是   false否
        id:""          //请求参数            自定义 例如index或者id
      },
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now() 
        }
      },
      endDateOpt:{
        disabledDate:(time)=>{
          return  time.getTime()< new Date(this.searchForm.startDate).getTime();
        }
      },
     
      resetFormStatus:false
  	}
  },

  methods: {
    seachData(){        //初始化数据
        var params=initDataTime(this.searchForm)||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.get('adminApi/admin/mortgage_order_inspection/list',params ).then((data)=>{
          if (data.success) {
              this.tableData = data.data.tableData;
              this.orderCode = data.data.carOrderStatusMap ;
              this.reviewStatus =data.data.reviewStatusMap ;
            }
        })
      },
      formIsEdit(e){       //点击按钮，表单是否查看还是编辑
        let value = e.currentTarget.innerText ;
        this.dialogSendData.dialogFormVisible=true;         
        this.mortgageOrderExtendId =  e.currentTarget.dataset.id     //传递给子组件的id
        this.buttonValue = value ;
     
        if(value==='查看'){  //可编辑
         this.dialogSendData.isAdd=true;
        }else{           //不可被编辑
         this.dialogSendData.isAdd=false;
        }

        
     },
     determine(row){  //准入库时，更改订单状态
        confirm(
          ()=>{
            agentHttp.putJson(`adminApi/admin/mortgage_order_inspection/in_stock/${row.mortgageOrderExtendId}`).then(data=>{
              if(data.success){
                this.$message.success(data.data||(flag));
                row.statusString = '待付款'
                this.seachData();
              }
            })
          },
          ()=>{
            this.$message.info('已取消'+flag);
          },
          "确认准入库吗?"
        )
        
     },
     getDates(time){    //格式化时间错
      return  timestampToTime(time)
    },
    addOrEdit(value){     //更改按钮的内容
        if(value=='10020'){
          return '添加'
        }else if(value=='10050'){
          return '编辑'
        }
    },
    debounceSeach(){      //input框内容发生改变时，调接口显示查询结果
      this.tableData.page=1;
      debounce(this.seachData(this.searchForm),1000)
    },
    resetSearchForm(formName){
      this.$refs[formName].resetFields();
      this.seachData()
    },
  }
}